import pandas as pd
import json

# 读取Excel文件
df = pd.read_excel('./data/Fund_Behavior.xlsx')

# 提取前20条记录
data = df.head(20)

# 定义一个空列表来存储转换后的记录
json_records = []

# 遍历DataFrame的每一行
for index, row in data.iterrows():
    # 创建一个字典来存储单个记录
    record = {
        'investor_id': str(row['Investor_ID']),
        'since': row['Longevity'].item(),
        'gender': '女' if row['Female'] == 1 else '男',
        'age': row['Age'].item(),
        'income': row['Income'].item(),
        'AUM': row['AUM'].item(),
        'profManage': row['ProfManage'].item(),
        'diversificatior': row['Diversification'].item(),
        'affordability': row['Affordability'].item(),
        'liquidity': row['Liquidity'].item(),
        'growth': row['Growth'].item(),
        'trustworthiness': row['Trustworthiness'].item(),
        'technology': row['Technology'].item(),
        'integrity': row['Integrity'].item(),
        'brandValue': row['BrandValue'].item()
    }
    # 添加记录到列表
    json_records.append(record)

# 将记录保存为JSON文件
with open('output.json', 'w', encoding='utf-8') as json_file:
    json.dump(json_records, json_file, ensure_ascii=False, indent=4)

print("JSON文件已成功保存。")
